﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace iTunesUpdater
{
  public class TrackInfo
  {
    public const char EscapeChar = '\\';
    public string FileName="";
    public string ShowName = "";
    public string Episode = "";
    public string PartNo = "";
    public string PartOf = "";
    public string Month = "";
    public string Day = "";
    public string Year = "";
    public string Name {
      get {
        if (PartNo != "")
          return Episode + " (" + PartNo + "/" + PartOf + ")";
        else
          return Episode;
      }
      set {
        Episode = value;
        if(ShowName == "") ShowName = value;
      }
    }

    public void SetItem(string token, string value) {
      if (token.Length == 2)
        SetItem(token[1], value);
      else if (token.Length == 1)
        SetItem(token[0], value);
    }

    public void SetItem(char token, string value) {
      switch (token) {
        case 's':
          ShowName = value;
          break;
        case 'e':
          Episode = value;
          break;
        case 'd':
          Day = value;
          break;
        case 'm':
          Month = value;
          break;
        case 'y':
          Year = value;
          break;
        case 'x':
          if (value.Contains('_')) {
            string[] parts = value.Split('_');
            PartNo = parts[0];
            PartOf = parts[1];
          }
          else
            PartNo = value;
          break;
        case 'n':
          PartOf = value;
          break;
      }
    }
  }
}
